package com.ftg.youx.demo.publishSubscribe;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 生产者  （发布者）
 *
 * @author 布衣
 */
public class Product {

    public static void main(String[] args) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setVirtualHost("/");
        factory.setUsername("guest");
        factory.setPassword("guest");
        try(
            Connection connection =  factory.newConnection();
            //创建频道
            Channel channel = connection.createChannel();
        ) {
            //创建交易所
            channel.exchangeDeclare("myExchange", "fanout");

//            for (int i = 0; i < 20000; i++) {
                //发送信息
                String message = "关于雷局的精典语录2";
                channel.basicPublish("myExchange","",null,message.getBytes());
                System.out.println("我发送完成了");
//            }

        } catch (IOException | TimeoutException e) {
            throw new RuntimeException(e);
        }
    }
}
